import time

from selenium import webdriver
from selenium.webdriver.common.by import By

options = webdriver.ChromeOptions()

options.page_load_strategy = "normal"  # 等待页面完全加载
# 创建浏览器驱动对象
driver = webdriver.Chrome(options=options)
# 隐式等待
url = r"https://www.bilibili.com/"
driver.get(url)
js1 = "window.scrollTo(0,10000)"
driver.execute_script(js1)
div_list = driver.find_elements(by=By.CSS_SELECTOR, value=".card-list>.video-card")  # class选择器+层次
print(len(div_list))
time.sleep(3)
for div in div_list:
    name = div.find_element(by=By.CSS_SELECTOR, value='.video-name').text
    up = div.find_element(by=By.CSS_SELECTOR, value='.up-name__text').text
    play_num = div.find_element(by=By.CSS_SELECTOR, value='.play-text').text
    like_num = div.find_element(by=By.CSS_SELECTOR, value='.like-text').text
    print(f"名称: {name}, up主: {up}, 播放数量: {play_num}, 评论数: {like_num}")

input("按任意键关闭")
# # 关闭驱动对象
driver.close()
driver.quit()
print("结束")
